package com.tin.config;

import com.tin.handler.JWTInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.awt.image.RescaleOp;
import java.util.Arrays;

/**
 * @author liming_oicq@163.com
 * @date 2018-10-13 02:01
 * 注册类
 */

@Configuration
public class WebConfiguration implements WebMvcConfigurer {


    //spring拦截器加载在springcontext之前，所以这里使用@Bean提前加载，否则会导致@AutoWired注入为空
    //@Bean
    JWTInterceptor jwtInterceptor() {
        return new JWTInterceptor();
    }

    @Autowired
    JWTInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册JWT拦截器，"/", "/user/login"请求不拦截
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/**")
                .excludePathPatterns(Arrays.asList("/", "/user/login", "/v2/api-docs"));
    }
}
